<template>
    <div id="ds7">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>运营分析平台</BreadcrumbItem>
            <BreadcrumbItem>拨打电话次数表</BreadcrumbItem>
        </Breadcrumb>
        拨打角色
        <Select v-model="type" style="width:200px;">
            <Option v-for="item in typeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select> &nbsp;
        被拨打角色
        <Select v-model="typeto" style="width:200px;">
            <Option v-for="item in typeListto" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select> &nbsp;
        是否下载
        <Select v-model="down" style="width:200px;">
            <Option v-for="item in downList" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select>
        &nbsp;
        <Input v-model="selectMobile" placeholder="被拨打手机号码" style="width: 150px"/>
        &nbsp;
        <Button type="info" @click="search()">查询</Button>


        <div style="margin-top: 10px">
            <Table :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
                   v-if="data&&data.length>0"></Table>

            <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
                  style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator v-if="data&&data.length>0"/>
            <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
                总计 {{pageTotal}} 条数据
            </div>
        </div>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>


    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                down: "1",
                downList: [
                    {
                        value: '1',
                        label: '是'
                    },
                    {
                        value: '2',
                        label: '否'
                    }
                ],
                type: "",
                typeList: [
                    {
                        value: '1',
                        label: '司机'
                    },
                    {
                        value: '2',
                        label: '配件商'
                    },
                    {
                        value: '3',
                        label: '修理'
                    },
                    {
                        value: '4',
                        label: '补胎'
                    },
                    {
                        value: '5',
                        label: '审车'
                    },
                    {
                        value: '6',
                        label: '加油'
                    },
                    {
                        value: '7',
                        label: '吊车'
                    }
                ], typeto: "",
                typeListto: [
                    {
                        value: '1',
                        label: '司机'
                    },
                    {
                        value: '2',
                        label: '配件商'
                    },
                    {
                        value: '3',
                        label: '修理'
                    },
                    {
                        value: '4',
                        label: '补胎'
                    },
                    {
                        value: '5',
                        label: '审车'
                    },
                    {
                        value: '6',
                        label: '加油'
                    },
                    {
                        value: '7',
                        label: '吊车'
                    }
                ],
                selectMobile: "",
                loading: false,
                pageTotal: 0,
                curPage: 0,
                columns: [
                    {
                        title: '拨打用户角色',
                        key: 'userType1'
                    },
                    {
                        title: '被拨打用户角色',
                        key: 'toUserType1'
                    },
                    {
                        title: '被拨打用户手机',
                        key: 'toMobile'
                    },
                    {
                        title: '拨打次数',
                        key: 'count'
                    }, {
                        title: '下载终端',
                        key: 'source1'
                    },
                    {
                        title: '被拨打人是否认真',
                        key: 'validStatus1'
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            search(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));

                if (this.type) {
                    param.append('userType', this.type + "");
                }
                if (this.typeto) {
                    param.append('toUserType', this.typeto + "");
                }
                if (this.selectMobile) {
                    param.append('toMobile', this.selectMobile + "");
                }

                param.append('downLoad', this.down + "");
                this.loading = true;
                Axios.post(ipServer + "statistical/selectCallLogList", param)
                        .then(res => {

                            if (res.data.code == 0) {

                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    if (res.data.data.result[i].toUserType == "1") {
                                        res.data.data.result[i].toUserType1 = "司机";
                                    }
                                    if (res.data.data.result[i].toUserType == "2") {
                                        res.data.data.result[i].toUserType1 = "配件商";
                                    }
                                    if (res.data.data.result[i].toUserType == "3") {
                                        res.data.data.result[i].toUserType1 = "修理";
                                    }
                                    if (res.data.data.result[i].toUserType == "4") {
                                        res.data.data.result[i].toUserType1 = "补胎";
                                    }
                                    if (res.data.data.result[i].toUserType == "5") {
                                        res.data.data.result[i].toUserType1 = "审车";
                                    }
                                    if (res.data.data.result[i].toUserType == "6") {
                                        res.data.data.result[i].toUserType1 = "加油";
                                    }

                                    if (res.data.data.result[i].validStatus == 0) {
                                        res.data.data.result[i].validStatus1 = "未认证";
                                    }
                                    if (res.data.data.result[i].validStatus == 1) {
                                        res.data.data.result[i].validStatus1 = "待认证";
                                    }
                                    if (res.data.data.result[i].validStatus == 2) {
                                        res.data.data.result[i].validStatus1 = "认证失败";
                                    }
                                    if (res.data.data.result[i].validStatus == 3) {
                                        res.data.data.result[i].validStatus1 = "认证成功";
                                    }
                                    res.data.data.result[i].source1 = "无";

                                    if (res.data.data.result[i].source == "1") {
                                        res.data.data.result[i].source1 = "Android";
                                    }
                                    if (res.data.data.result[i].source == "2") {
                                        res.data.data.result[i].source1 = "Android";
                                    }


                                    if (res.data.data.result[i].source == "7") {
                                        res.data.data.result[i].toUserType1 = "吊车";
                                    }


                                    if (res.data.data.result[i].userType == "1") {
                                        res.data.data.result[i].userType1 = "司机";
                                    }
                                    if (res.data.data.result[i].userType == "2") {
                                        res.data.data.result[i].userType1 = "配件商";
                                    }
                                    if (res.data.data.result[i].userType == "3") {
                                        res.data.data.result[i].userType1 = "修理";
                                    }
                                    if (res.data.data.result[i].userType == "4") {
                                        res.data.data.result[i].userType1 = "补胎";
                                    }
                                    if (res.data.data.result[i].userType == "5") {
                                        res.data.data.result[i].userType1 = "审车";
                                    }
                                    if (res.data.data.result[i].userType == "6") {
                                        res.data.data.result[i].userType1 = "加油";
                                    }
                                    if (res.data.data.result[i].userType == "7") {
                                        res.data.data.result[i].userType1 = "吊车";
                                    }
                                }
                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                                if (this.data.length == 0)
                                    this.$Message.info("查询数据不存在!");
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");

                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            pageChange(page){
                this.getData(page);
            },
            getData(page){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (page) {
                    param.append('pageId', page + "");
                }
                if (this.type) {
                    param.append('userType', this.type + "");
                }
                if (this.typeto) {
                    param.append('toUserType', this.typeto + "");
                }
                if (this.selectMobile) {
                    param.append('toMobile', this.selectMobile + "");
                }

                param.append('downLoad', this.down + "");


                this.loading = true;
                Axios.post(ipServer + "statistical/selectCallLogList", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {

                                    if (res.data.data.result[i].toUserType == "1") {
                                        res.data.data.result[i].toUserType1 = "司机";
                                    }
                                    if (res.data.data.result[i].toUserType == "2") {
                                        res.data.data.result[i].toUserType1 = "配件商";
                                    }
                                    if (res.data.data.result[i].toUserType == "3") {
                                        res.data.data.result[i].toUserType1 = "修理";
                                    }
                                    if (res.data.data.result[i].toUserType == "4") {
                                        res.data.data.result[i].toUserType1 = "补胎";
                                    }
                                    if (res.data.data.result[i].toUserType == "5") {
                                        res.data.data.result[i].toUserType1 = "审车";
                                    }
                                    if (res.data.data.result[i].toUserType == "6") {
                                        res.data.data.result[i].toUserType1 = "加油";
                                    }

                                    if (res.data.data.result[i].validStatus == 0) {
                                        res.data.data.result[i].validStatus1 = "未认证";
                                    }
                                    if (res.data.data.result[i].validStatus == 1) {
                                        res.data.data.result[i].validStatus1 = "待认证";
                                    }
                                    if (res.data.data.result[i].validStatus == 2) {
                                        res.data.data.result[i].validStatus1 = "认证失败";
                                    }
                                    if (res.data.data.result[i].validStatus == 3) {
                                        res.data.data.result[i].validStatus1 = "认证成功";
                                    }
                                    res.data.data.result[i].source1 = "无";

                                    if (res.data.data.result[i].source == "1") {
                                        res.data.data.result[i].source1 = "Android";
                                    }
                                    if (res.data.data.result[i].source == "2") {
                                        res.data.data.result[i].source1 = "Android";
                                    }


                                    if (res.data.data.result[i].source == "7") {
                                        res.data.data.result[i].toUserType1 = "吊车";
                                    }


                                    if (res.data.data.result[i].userType == "1") {
                                        res.data.data.result[i].userType1 = "司机";
                                    }
                                    if (res.data.data.result[i].userType == "2") {
                                        res.data.data.result[i].userType1 = "配件商";
                                    }
                                    if (res.data.data.result[i].userType == "3") {
                                        res.data.data.result[i].userType1 = "修理";
                                    }
                                    if (res.data.data.result[i].userType == "4") {
                                        res.data.data.result[i].userType1 = "补胎";
                                    }
                                    if (res.data.data.result[i].userType == "5") {
                                        res.data.data.result[i].userType1 = "审车";
                                    }
                                    if (res.data.data.result[i].userType == "6") {
                                        res.data.data.result[i].userType1 = "加油";
                                    }
                                    if (res.data.data.result[i].userType == "7") {
                                        res.data.data.result[i].userType1 = "吊车";
                                    }
                                }
                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>